package com.chtw.edu.service.impl;

import com.chtw.edu.bean.User;
import com.chtw.edu.service.UserService;
import com.chtw.edu.utils.jwt.JWTUtil;
import com.chtw.edu.utils.myException.JwtException;
import org.apache.tomcat.jni.Error;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * @author chtw
 * @date 2020-10-11 17:30
 */
@Service
public class UserServiceImpl implements UserService {


    @Override
    public User authentication(User user, HttpSession session) throws Exception {
        // 认证密码用户名, 这里数据库进行验证，先不做这一步
        String token = JWTUtil.sign(user.getUserName(), user.getPassword());
        if(token != null){
            user.setToken(token);
            // 密码放空
            user.setPassword("");
            user.setUserId("jkjkjk");
            user.setUserName("hjh");
            session.setAttribute("token", token);
            return user;
        }else {
            throw JwtException.tokenError("授权失败");
        }
    }
}
